<?php

	namespace app\ajax\controller;

	use Qiniu\Auth;
	use think\Loader;

	class Qiniu{
		public function getToken(){
			Loader::import('Qiniu.functions');

			// 需要填写你的 Access Key 和 Secret Key
			$accessKey = config('qiniu.ACCESSKEY');
			$secretKey = config('qiniu.SECRETKEY');
			// 构建鉴权对象
			$auth = new Auth($accessKey, $secretKey);

			$expires = 7200;
			$returnBody = '{"key":"$(key)","hash":"$(etag)","fsize":$(fsize),"bucket":"$(bucket)","name":"$(x:name)"}';
			$policy = array('returnBody' => $returnBody);
			// 要上传的空间
			$bucket = config('qiniu.BUCKET');
			$token = $auth->uploadToken($bucket, null, $expires, $policy, true);
			return ['token'=>$token,'domain'=>config('qiniu.DOMAIN')];
		}
	}